package p270jp.pxv.android.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import java.util.Calendar;
import java.util.List;
import p014ae.AbstractActivityC0177w2;
import p047bg.C1124a;
import p090d0.C2518n;
import p111dl.RankingService;
import p270jp.pxv.android.R;
import p270jp.pxv.android.domain.model.XRestrict;
import p270jp.pxv.android.legacy.constant.ContentType;
import p307l9.EdgeTreatment;
import p314lg.ActivityRankingBinding;
import p370ni.RankingCategory;
import p547uh.BaseRecyclerFragment;
import p547uh.IllustRankingFragment;
import p547uh.NovelRankingFragment;

/* renamed from: jp.pxv.android.activity.RankingActivity */
/* loaded from: classes2.dex */
public class RankingActivity extends AbstractActivityC0177w2 {

    /* renamed from: b0 */
    public ActivityRankingBinding f18561b0;

    /* renamed from: jp.pxv.android.activity.RankingActivity$a */
    /* loaded from: classes2.dex */
    public class C4074a extends TabLayout.C2210j {

        /* renamed from: b */
        public final /* synthetic */ C4075b f18562b;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4074a(ViewPager viewPager, C4075b bVar) {
            super(viewPager);
            RankingActivity.this = r1;
            this.f18562b = bVar;
        }

        @Override // com.google.android.material.tabs.TabLayout.C2210j, com.google.android.material.tabs.TabLayout.AbstractC2201c
        /* renamed from: a */
        public void mo4699a(TabLayout.C2207g gVar) {
            Fragment m = this.f18562b.mo4758m(RankingActivity.this.f18561b0.f21560u.getCurrentItem());
            if (m instanceof BaseRecyclerFragment) {
                ((BaseRecyclerFragment) m).mo1600a();
            }
        }
    }

    /* renamed from: jp.pxv.android.activity.RankingActivity$b */
    /* loaded from: classes2.dex */
    public static class C4075b extends FragmentStatePagerAdapter {

        /* renamed from: j */
        public final Context f18564j;

        /* renamed from: k */
        public List<RankingCategory> f18565k;

        /* renamed from: l */
        public ContentType f18566l;

        public C4075b(FragmentManager fragmentManager, ContentType contentType, Context context) {
            super(fragmentManager);
            this.f18566l = contentType;
            this.f18564j = context;
            this.f18565k = RankingCategory.f23731f.m3360c(contentType, XRestrict.GENERAL, true);
        }

        @Override // p094d4.PagerAdapter
        /* renamed from: c */
        public int mo938c() {
            return this.f18565k.size();
        }

        @Override // p094d4.PagerAdapter
        /* renamed from: e */
        public CharSequence mo4759e(int i) {
            return this.f18564j.getString(this.f18565k.get(i).f23753b);
        }

        @Override // androidx.fragment.app.FragmentStatePagerAdapter
        /* renamed from: m */
        public Fragment mo4758m(int i) {
            RankingCategory cVar = this.f18565k.get(i);
            ContentType contentType = this.f18566l;
            if (contentType == ContentType.ILLUST || contentType == ContentType.MANGA) {
                if (!cVar.f23756e) {
                    return IllustRankingFragment.m1632h(cVar, null);
                }
                Calendar instance = Calendar.getInstance();
                instance.add(5, -2);
                return IllustRankingFragment.m1632h(cVar, instance.getTime());
            } else if (contentType != ContentType.NOVEL) {
                throw new IllegalStateException("invalid content type");
            } else if (!cVar.f23756e) {
                return NovelRankingFragment.m1520w(cVar, null);
            } else {
                Calendar instance2 = Calendar.getInstance();
                instance2.add(5, -2);
                return NovelRankingFragment.m1520w(cVar, instance2.getTime());
            }
        }
    }

    /* renamed from: e1 */
    public static Intent m4760e1(Context context, ContentType contentType) {
        EdgeTreatment.m3909i(contentType);
        Intent intent = new Intent(context, RankingActivity.class);
        intent.putExtra("content_type", (Parcelable) contentType);
        return intent;
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f18561b0 = (ActivityRankingBinding) DataBindingUtil.m11369d(this, R.layout.activity_ranking);
        ContentType contentType = (ContentType) getIntent().getParcelableExtra("content_type");
        this.f18757A.m6525e(((RankingService) C2518n.m7641d(RankingService.class)).m7228a(contentType));
        C1124a.m10197Q(this, this.f18561b0.f21559t, RankingCategory.f23731f.m3361b(contentType));
        C4075b bVar = new C4075b(m11131K0(), contentType, this);
        this.f18561b0.f21560u.setAdapter(bVar);
        ActivityRankingBinding f1Var = this.f18561b0;
        f1Var.f21558s.setupWithViewPager(f1Var.f21560u);
        ActivityRankingBinding f1Var2 = this.f18561b0;
        f1Var2.f21558s.setOnTabSelectedListener((TabLayout.AbstractC2202d) new C4074a(f1Var2.f21560u, bVar));
    }
}
